<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>个人资料</title>
    <link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
    <link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
    <link rel="stylesheet" href="../assets/app/css/app.css" />
    <script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/jquery.form.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/common.js"></script>

<style>
.listitem li{background:#F9F9F9;padding:0 12px;}
.listitem li .text i{vertical-align: middle;}
.listitem li a{padding:12px 0;display: block;}
</style>
</head>
<body>

<div id="ios-top-box">
<div id="header" class="bar bar-nav">
    <div class="titlebar">
        <a href="javascript:appClose('basedata',api);"><i class="iconfont iconline-arrow-left"></i></a>
        <h1>个人资料</h1>
    </div>
</div>
</div>


<script type="text/html" id="sign_template">
    <div class="tpl-box" style="width:280px;">
        <div class="tpl-box-title">编辑个性签名</div>
        <div class="tpl-box-main">
        <textarea class="full-width" rows="5" maxlength="80" style="resize:none;font-size:13px;padding-top:10px;padding-bottom:10px;" id="qianmingTextarea" name="qianming" placeholder="字数限2～80字"></textarea>
        </div>
        <div id="win-bottom" class="winbox2">
            <div class="win-bottom-left left-btn" id="sign_cancel">取消</div>
            <div class="win-bottom-right right-btn" id="sign_save">保存</div>
        </div>
    </div>
</script>
				
<section class="common-section" style="margin-bottom:0px;margin-top:64px !important;">
	<div class="scroller">
			<form action="" id="faceform" method="post" enctype="multipart/form-data">
			 <input style="display:none;" type="file" name="Filedata" id="upload" />
			</form>
		<div id="uploadFace" style="background:#c40c00;padding:30px 0 15px 0;">
			<div id="faceimg" style="width:70px;height:70px;background:url(../image/face.png);background-size:70px;margin:0 auto;border-radius:50%;"></div>
			<p style="text-align:center;color:#fff;padding:7px 0;" id="user-p"></p>
		</div>
			<ul class="listitem user-listitem-line">
				<li>
				 <a href="javascript:;" id="nickname">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">昵称<span style="float:right;"></span></div>
				  </a>
				</li>
<!-- 
				<li>
				 <a href="javascript:randomSwitchBtn('sign',api);" id="sianmin">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">个性签名</div>
				  </a>
				</li>
 -->
				<li>
				 <a href="javascript:;" id="mobile">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">手机号：<span style="float:right;"></span></div>
				  </a>
				</li>
				<li>
				 <a href="javascript:;" id="email">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">邮箱：<span style="float:right;"></span></div>
				  </a>
				</li>
				<li>
				 <a href="javascript:randomSwitchBtn('setpwd',api);">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">重置密码</div>
				  </a>
				</li>
				<!--
				<li>
				 <a href="javascript:randomSwitchBtn('commissions',api);">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">佣金明细</div>
				  </a>
				</li>
				<li>
				 <a href="javascript:randomSwitchBtn('cashout',api);">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">申请提现</div>
				  </a>
				</li>
				<li>
				 <a href="javascript:randomSwitchBtn('cashoutrecord',api);">
					<i class="ricon iconfont iconline-arrow-right"></i>
					<div class="text">提现记录</div>
				  </a>
				</li>
				-->
			</ul>
	</div>

</section>
<script type="text/javascript">
apiready = function(){
$(function(){
    var userinfo = localData.get('userinfo');
    var userinfo = JSON.parse(userinfo);
    
    if(userinfo != undefined && userinfo != '' && userinfo != null){
        var userp = userinfo['mobile']?userinfo['mobile']:userinfo['email'];
        $('#user-p').html('用户：'+userp);
        
        GetJPData(config.url+'/app.php?act=updateuser&uid='+userinfo.uid,{},function(data){
            $('#nickname span').html(data.data.username);
            $('#sianmin div.text').attr('title',data.data.qianming);
            $('#mobile span').html(data.data.mobile);
            $('#email span').html(data.data.email);
            $('#faceimg').css('background','url('+config.upload_url+'/'+data.data.thumb+')').css('background-size','70px');
        });
        
$('#email').click(function(){
    var text = $(this).find('span').text();
api.prompt({
    title:'设置邮箱',
    text:text,
    type:'email',
    buttons: ['确定', '取消']
},function( ret, err ){
    if(ret['buttonIndex'] == 1){
        
        var email = ret['text'];
        if(!checkEmail(email)){
            appToast('邮箱格式不正确');
            return false;
        }
        api.showProgress({title : '正在保存...',text : ''});
        PostData(config.url+'/app.php?act=set_email&uid='+userinfo['uid'],{param: email},function(data){
            api.hideProgress();
            if(data['status'] == 1){
               $('#email span').text(email);
                userinfo['email'] = email;
                localData.set('userinfo',JSON.stringify(userinfo));
            }
            appToast(data['msg']);
        });
        
    }else{
        
        //
    }
});
});


$('#mobile').click(function(){
    var text = $(this).find('span').text();
api.prompt({
    title:'设置手机号码',
    text:text,
    type:'number',
    buttons: ['确定', '取消']
},function( ret, err ){
    if(ret['buttonIndex'] == 1){
        
        var mobile = ret['text'];
        if(!checkMobile(mobile)){
            appToast('手机号码格式不正确');
            return false;
        }
        api.showProgress({title : '正在保存...',text : ''});
        PostData(config.url+'/app.php?act=set_mobile&uid='+userinfo['uid'],{param: mobile},function(data){
            api.hideProgress();
            if(data['status'] == 1){
               $('#mobile span').text(mobile);
                userinfo['mobile'] = mobile;
                localData.set('userinfo',JSON.stringify(userinfo));
            }
            appToast(data['msg']);
        });
        
    }else{
        
        //
    }
});
});

$('#nickname').on('click',function(){
var text = $(this).find('span').text();
api.prompt({
    title:'设置昵称',
    text:text,
    buttons: ['确定', '取消']
},function( ret, err ){
    if(ret['buttonIndex'] == 1){
                var nickname = ret['text'];
                if(nickname == ''){
                    appToast('请输入昵称');
                    return false;
                }
                if(nickname.length > 20 || nickname.length < 2){
                    appToast('昵称长度2～20位之间');
                    return false;
                }
                api.showProgress({title : '正在保存...',text : ''});
                PostData(config.url+'/app.php?act=set_nickname&uid='+userinfo['uid'],{param: nickname},function(data){
                    api.hideProgress();
                        if(data['status'] == 1){
                            $('#nickname span').text(nickname);
                            userinfo['username'] = nickname;
                            localData.set('userinfo',JSON.stringify(userinfo));
                        }
                    appToast(data['msg']);
                });
         
    }else{
         //
    }
});
            
});
        
       
        var html = '<button id="selecteImg" class="common-btn">选择图片</button>';
    	$('#faceimg').on('click', function(){
    	    zoom();
    	    openBottomBox(html);
    		return false;
    	});
    	
        $('body').on('click','#bottom-cancel button.common-btn',function(){
            bottomBox_close();
        });
        function bottomBox_close(){
            var bottom_box_height = $('#bottom-box').height();
            $('#bottom-box').animate({
                'bottom' : -bottom_box_height
            }, 'fast',function(){
                $(this).hide();
                $('#zoom').fadeOut();
            });
        }
        $('body').on('click','#zoom',function(){
            bottomBox_close();
        });
    	
    	$('body').on('click','#selecteImg',function(){
    	    $('#upload').click();
    	});
    	$('#upload').change(function(event) {
    		$('#faceform').ajaxSubmit({
    			type : 'post',
    			url : config.url+'/app.php?act=uplaodface&uid='+userinfo['uid'],
    			beforeSend : function(){
    			    api.showProgress({title : '正在上传...',text : ''});
    			},
    			success : function(res){
    			    api.hideProgress();
    				if(res['status'] == 0){
    					appToast(res['msg']);
    				}else if(res['status'] == 1){
    				    var path = config.url+res['path'];
    				    
    				    userinfo['face'] = res['path2'];
    				    localData.set('userinfo',JSON.stringify(userinfo));
    					$('#faceimg').css('background','url('+path+')').css('background-size','70px');
    				}
    				bottomBox_close();
    				zoom();
    			}
    		});
    	});
	}else{
	    randomSwitchBtn('login',api);
	}
});
};
</script>
</body>
</html>